﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
</head>
<body class="layui-padding-3">
    <h3 style="color: #34c38f">
        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #dcccc0;cursor:pointer" onclick="location.href='/BOM/BOMSearch'"> 返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;物料清单头信息&nbsp;(<i class="layui-icon layui-icon-backspace"></i>)
    </h3>
    <hr style="color: #34c38f" />
    <form class="layui-form" action="">
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">物料清单编码</label>
                <div class="layui-input-block">
                    <input type="text" name="boMInformCode" id="boMInformCode" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>

        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">物料清单版本</label>
                <div class="layui-input-block">
                    <input type="text" name="boMInformVersion" id="boMInformVersion" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">物料选择</label>
                <div class="layui-input-inline">
                    <select name="materialId" id="materialId" lay-verify="required" lay-search lay-filter="demoselect">
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">物料清单描述</label>
                <div class="layui-input-block">
                    <input type="text" name="boMInformDec" id="boMInformDec" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">物料单位</label>
                <div class="layui-input-block">
                    <input type="text" name="materialUnit" id="materialUnit" placeholder="请输入" readonly class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">物料规格</label>
                <div class="layui-input-block">
                    <input type="text" name="materialSpecifications" id="materialSpecifications" readonly placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">制单人</label>
                <div class="layui-input-block">
                    <input type="text" name="singleMaker" id="singleMaker" readonly value="hhx123" placeholder="请输入" class="layui-input" lay-affix="clear">
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">制单部门</label>
                <div class="layui-input-inline">
                    <select name="departmentId" id="departmentId" lay-verify="required" lay-search lay-filter="demo1select">
                        <option value="1" selected>仓储部</option>
                    </select>
                </div>
            </div>
        </div>
        <hr />

        <div class="layui-col-md4">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="isStatus" id="isStatus" lay-verify="required" lay-search>
                        <option value="">请选择</option>
                        <option value="1">有效</option>
                        <option value="2">无效</option>
                    </select>
                </div>
            </div>
        </div>
        <br />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="component" class="layui-btn" lay-submit lay-filter="demo-val">
                    保存
                    <i class="layui-icon layui-icon-right"></i>
                </button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button style="margin-left: 1000px" type="submit" class="layui-btn layui-bg-blue" lay-submit lay-filter="search">
                    提交<i class="layui-icon layui-icon-right"></i>
                </button>
            </div>
        </div>
    </form>

    <h3 style="color: #50a5f1">物料清单行信息</h3>
    <hr />
    <h4>行信息</h4>
    <div class="layui-btn-container">
        <button style="margin-left: 1100px" type="button" class="layui-btn layui-bg-blue" lay-on="test-page-custom">
            <span><i class="layui-icon layui-icon-addition"></i>新增资源</span>
        </button>
    </div>
    <table class="layui-hide" id="ID-table-demo-search"></table>

    <!-- 弹出层 -->
    <script>
        layui.use(['form', 'laydate', 'util','table'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            SearchMaterial()//物料选择

            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 2,
                        title: '资源行添加',
                        shadeClose: true,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['900px', '600px'],
                        content: '/Process/ResouresAdd'
                    });
                },
            });

            //物料管理添加
            // 表单取值
            layui.$('#component').on('click', function () {
                var data = form.val('demo-val-filter');
            });

            // 添加提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值;
                var username=localStorage.getItem('userName');
                console.log(username);
                field.createdOwner = username;
                field.createdTime = "" || new Date().toISOString();
                field.updateOwner = "" || null;
                field.updateTime = "" || new Date().toISOString();
                field.examineOwner = "" || null;
                field.examineTime = "" || new Date().toISOString();
                field.isDel = 1;
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RedDragonWrite'+"/api/BoMs/AddBoM",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg ,{ icon: 6, time: 1000 });
                        Seach()
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });

            //物料选择下拉框绑定
            function SearchMaterial() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/Process/SearchLogistics",
                    type: 'GET',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.materialId + '">' + item.materialName + '</option>';
                        });
                        $('#materialId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                });
            }

            //下拉框获取值
            form.on('select(demoselect)', function (data) {
                materialId = data.value;
                console.log(materialId)
                MaterialUnit()//物料单位
                MaterialSpecifications()//物料规格
                SingleMaker()//制单人
            });

            //物料单位
            function MaterialUnit() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchMaterialInfor",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#materialUnit').val(res.data.materialUnitName);
                    }
                });
            }

            //物料规格
            function MaterialSpecifications() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchMaterialInfor",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#materialSpecifications').val(res.data.specifications);
                    }
                });
            }
            //制单人
            function SingleMaker() {
                var materialId = $('#materialId').val();
                console.log(materialId)
                var obj = {
                    MaterialId: materialId
                }
                $.ajax({
                    url: '@ViewBag.RedDragonWrite' + "/api/BoMs/SearchMaterialInfor",
                    type: 'GET',
                    data: obj,
                    async: false,
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        $('#singleMaker').val(localStorage.getItem('userName'));
                    }
                });
            }

             // 搜索提交
            function Seach() {
                $.ajax({
                    url:'@ViewBag.RedDragonWrite'+"/api/ProductionTasks/SearchProductionTasks",
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [[
                                { field: 'materialId', title: '序号', width: 80 },
                                { field: 'materialId', title: '顺序', width: 120 },
                                { field: 'materialId', title: '工序', width: 120 },
                                { field: 'materialCode', title: '物料编码', width: 120 },
                                { field: 'materialName', title: '物料名称', width: 120 },
                                { field: 'materialName', title: 'Bom版本', width: 120 },
                                { field: 'specifications', title: '单位', width: 100 },
                                { field: 'specifications', title: '规格', width: 100 },
                                { field: 'productionQuantity', title: '数量', width: 100 },
                                { field: 'productionQuantity', title: '生产前置期', width: 100 },
                                { field: 'createdOwner', title: '创建人', width: 100 },
                                {field:'createdTime', width:150, title: '创建时间',templet: '<div>{{ layui.util.toDateString(d.createdTime, "yyyy-MM-dd HH:mm:ss") }}</div>'},
                                { field: 'processDetailStateName', title: '状态', width: 100 },
                                {
                                    fixed: 'right',
                                    title: '操作',
                                    width: 134,
                                    minWidth: 125,
                                    templet: '#toolDemo',
                                },
                            ]],
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };

        })

    </script>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
          <a onclick="" style="color:cornflowerblue;">编辑</a>
          <br />
          <a onclick="" style="color:red">删除</a>
        </div>
    </script>
</body>
</html>
<script>



</script>